/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle
 * @since : 2015-05-08 16:54:15
 * @filename : Gruntfile.js
 * @version : 
 * @description : 
 */

module.exports = function (grunt) {
 
  grunt.initConfig({
    
    pkg: grunt.file.readJSON('package.json'),
 
    less: { 
        target: { 
              expand: true, 
              cwd: 'src', 
              src: ['**/*.less'], 
              dest: 'src', 
              ext: '.css' 
        }
    },
    /*
    concat: {
      options: {
         separator: ';'
      },
      target: {
        src: [''],
        dest: ''
      }
    },
    */
    uglify: {
      options: {
         mangle: false, 
      },
      target: {
            files: [{
              expand: true,
              cwd: 'src',
              src: ['**/*.js','!**/*.min.js'],
              dest: 'dist'
            }],
      }
    },
    
    cssmin: {
        target: {
            files: [{
              expand: true,
              cwd: 'src',
              src: '**/*.css',
              dest: 'dist',
            }]
        },
    },
    
    imagemin: {      
        target: {
            options: {
                //优化级别1-7，默认是3，效果不明显                        
                optimizationLevel: 3,  
            },
            files: [{
                expand: true,
                cwd: "src",
                src: ['**/*.{png,jpg,gif}'],
                dest: "dist"
            }]
        },
     },

     copy: {
          target: {
            expand: true,
            cwd: 'src',
            src: ['**/*.tpl','**/*.min.js'],
            dest: 'dist',
            //flatten: true,
            //filter: 'isFile',
          },
     },
   
     htmlmin: {                                   
        target: {                                     
          options: {                                
            removeComments: true,
            collapseWhitespace: true
          }, 
          files: [
            {
              expand: true, 
              cwd: 'src', 
              src: ['**/*.html'],
              dest: 'dist'
            }
          ]
        }
     },
  
     //watch插件的配置信息,监听测试不是每次修改都监听的到？还需要在测试
     /*
     watch: {
          scripts: { 
            files: ['src/zepto/*.js'], 
            tasks: ['default'], 
          },
              
          src: {
            files: ['src/zepto/*.js','src/resource/css/*.css','src/resource/img/*.*'],
            tasks: ['default'],
          } 
     }
     */
  });
  // 加载提供任务的插件
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-less');
  //grunt.loadNpmTasks('grunt-contrib-watch');
  //grunt.loadNpmTasks('grunt-newer');

  // 默认任务
  //grunt.registerTask('html', ['htmlmin:target']);
  //grunt.registerTask('lesscss', ['less:target']);//less关键字不能做任务，被坑惨了
  grunt.registerTask('default', ['less:target',/*'concat:target',*/'uglify:target','cssmin:target','imagemin:target','copy:target','htmlmin:target']);
}


